package com.heihei.web.config;

import com.heihei.web.filter.TimeFilter;
import com.heihei.web.interceptor.TimeInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.ArrayList;
import java.util.List;


@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
	
	@Autowired
	private TimeInterceptor timeInterceptor;

	/**
	 * 添加拦截器
	 *
	 * @param registry
	 * @Return
	 * @throws
	 * @author duanhengfei
	 * @date 2021年03月27日 16:04:00
	 */
//	@Override
//	public void addInterceptors(InterceptorRegistry registry) {
//		registry.addInterceptor(timeInterceptor);
//	}


	/**
	 * 如需配置针对于异步接口的拦截器，则需要用 configureAsyncSupport
	 *
	 * @param configurer
	 * @Return
	 * @throws
	 * @author duanhengfei
	 * @date 2021年03月28日 11:37:29
	 */
	@Override
	public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
		//configurer.registerCallableInterceptors();
		//configurer.registerCallableInterceptors()

		//线程池
//		configurer.setTaskExecutor();

	}

	/**
	 * 过滤器  配置测试  （@Bean 注解，加上即生效）
	 *
	 * @param
	 * @Return {@link FilterRegistrationBean}
	 * @throws
	 * @author duanhengfei
	 * @date 2021年03月27日 15:53:03
	 */
//	@Bean
	public FilterRegistrationBean timeFilter() {
		
		FilterRegistrationBean registrationBean = new FilterRegistrationBean();
		
		TimeFilter timeFilter = new TimeFilter();
		registrationBean.setFilter(timeFilter);

		//在这里可以控制，要过滤的url
		List<String> urls = new ArrayList<>();
		urls.add("/*");
		registrationBean.setUrlPatterns(urls);
		
		return registrationBean;
		
	}

}
